{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "346b91fb",
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "from transformers import AutoTokenizer, AutoConfig, AutoModelForSequenceClassification\n",
    "from bidirectional_mistral import MistralBiForMNTP\n",
    "from transformers.trainer_utils import get_last_checkpoint"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "aef15969",
   "metadata": {},
   "outputs": [],
   "source": [
    "MistralBiForMNTP.register_for_auto_class()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "871addf6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'mistral-64M-mlm/checkpoint-65000'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "checkpoint = get_last_checkpoint('mistral-64M-mlm')\n",
    "checkpoint"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "dd4446c2",
   "metadata": {},
   "outputs": [],
   "source": [
    "model = MistralBiForMNTP.from_pretrained(checkpoint)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "961e35d9",
   "metadata": {},
   "outputs": [],
   "source": [
    "tokenizer = AutoTokenizer.from_pretrained(checkpoint)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "81df650d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "2b34ec913d0b436da435d5f2197947b7",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "model.safetensors:   0%|          | 0.00/257M [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "CommitInfo(commit_url='https://huggingface.co/mesolitica/malaysian-mistral-64M-MLM-512/commit/9611a59f4dc02f668c7648e769081605e1699524', commit_message='Upload MistralBiForMNTP', commit_description='', oid='9611a59f4dc02f668c7648e769081605e1699524', pr_url=None, pr_revision=None, pr_num=None)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.push_to_hub('mesolitica/malaysian-mistral-64M-MLM-512')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "81300e69",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "CommitInfo(commit_url='https://huggingface.co/mesolitica/malaysian-mistral-64M-MLM-512/commit/9ea4893d8ea3e160d750bae43dbbf666ac242ec7', commit_message='Upload tokenizer', commit_description='', oid='9ea4893d8ea3e160d750bae43dbbf666ac242ec7', pr_url=None, pr_revision=None, pr_num=None)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tokenizer.push_to_hub('mesolitica/malaysian-mistral-64M-MLM-512')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
